package org.example.code.test2024.ten_mouth;

import java.util.*;

public class test1011 {

    public ListNode modifiedList(int[] nums, ListNode head) {
        ListNode node = new ListNode();
        node.next = head;
        List<Integer> list = new ArrayList<>();
        for(int a:nums){
            list.add(a);
        }
        ListNode cur = node;
        while(cur.next!=null){
            if(list.contains(cur.val)){
                cur.next=cur.next.next;
            }else{
                cur=cur.next;
            }
        }
        return node.next;
    }


    public int minTime(int[] time, int m) {
        if(time.length<=m){
            return 0;
        }
        int l = 0, r = Arrays.stream(time).sum();
        while(l<r){
            int mid = (l+r)/2;
            if(check(time,mid,m)){
                r = mid;
            }else{
                l = mid + 1;
            }
        }
        return l;
    }

    private boolean check(int[] time, int maxTime, int m) {
        int days = 1;
        int curr = 0;
        int sum = 0;
        int max = 0;
        while(curr<time.length){
            sum = sum + time[curr];
            max = Math.max(time[curr],max);
            if(sum - max > maxTime){
                days++;
                if(days>m){
                    return false;
                }
                sum = time[curr];
                max = sum;
            }
            curr++;
        }
        return true;
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNextLine()){
            String line = in.nextLine();
            test1011 main = new test1011();
            line.substring(0,1);
            line.substring(line.length()-1,line.length());
            String reverse = main.reverse(line);
            System.out.println(reverse);
        }
    }

    private String reverse(String line){
        String[] split = line.split(" ");
        List<String> list = new ArrayList<>();
        for(String str:split){
            if(str.contains("ali")){
                String[] split1 = str.split("ali");
                StringBuilder sb = new StringBuilder();
                for (String s : split1) {
                    if (s.equals(""))
                        continue;
                    String reverse = reverse(s);
                    sb.append(change(reverse));
                    sb.append("ali");
                }
                list.add(sb.toString());
            }else{
                StringBuilder sb = new StringBuilder(str);
                StringBuilder newStr = sb.reverse();
                list.add(change(newStr.toString()));
            }
        }
        StringBuilder sb = new StringBuilder();
        for(int i=list.size()-1;i>=0;i--){
            if(i==0){
                sb.append(list.get(i));
            }else{
                String str = list.get(i)+" ";
                sb.append(str);
            }
        }
        return sb.toString();
    }

    private String change(String str){
        char[] charArray = str.toCharArray();
        StringBuilder sb = new StringBuilder();
        for(int i=0;i<str.length();i++){
            if(str.charAt(i)<='z'&&str.charAt(i)>='a'){
                charArray[i]= (char) (charArray[i]+('A'-'a'));
            }
            sb.append(charArray[i]);
        }
        return sb.toString();
    }
}
